package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysTestRecord;
import com.ruoyi.system.mapper.SysTestRecordMapper;
import com.ruoyi.system.service.ITestRecordService;

/**
 * 学员记录信息
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/record")
public class SysTestRecordController extends BaseController
{
    @Autowired
    private ITestRecordService testRecordService;
    @Autowired
    private SysTestRecordMapper sysTestRecordMapper;

    /**
     * 获取学员记录列表
     */
    @PreAuthorize("@ss.hasPermi('student:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysTestRecord entity, Date beginTime, Date endTime, Integer pageNum, Integer pageSize, String unitName, String studentName)
    {
        List<SysTestRecord> list = testRecordService.list(entity, beginTime, endTime, pageNum, pageSize, unitName, studentName);
        Integer total = sysTestRecordMapper.count(entity, beginTime, endTime, unitName, studentName);
        return getDataTable(list, total.longValue());
    }

    /**
     * 导出学员记录
     */
    @PreAuthorize("@ss.hasPermi('student:record:export')")
    @PostMapping("/export")
    @Log(title = "学员记录", businessType = BusinessType.EXPORT)
    public void export(HttpServletResponse response, SysTestRecord testRecord, String unitName, String studentName)
    {
        List<SysTestRecord> list = testRecordService.list(testRecord, null, null, null, 10000, unitName, studentName);
        ExcelUtil<SysTestRecord> util = new ExcelUtil<SysTestRecord>(SysTestRecord.class);
        util.exportExcel(response, list, "学习记录");
    }
}